package com.shelpe.services.algorithm.autoDrive;

import java.util.ArrayList;
import java.util.List;

import com.shelpe.services.algorithm.client.InsightWordData;
import com.shelpe.services.algorithm.entity.batis.Keyword;
import com.shelpe.services.algorithm.entity.batis.RptKeyword;
import com.shelpe.services.algorithm.entity.jpa.Adgroup;
import com.shelpe.services.algorithm.entity.jpa.AutoProductQueue;

import lombok.Data;

@Data
public class AutoDriveSustainer {

	private AutoProductQueue queue;
	private Adgroup adgroup;
	
	private List<Keyword> keywords;
	
	private List<RptKeyword> last3daysReport;
	private List<RptKeyword> last7daysReport;
	
	private List<InsightWordData> insightDatas = new ArrayList<InsightWordData>();
	
	private boolean added;
	private boolean priced;
	private boolean removed;
	
	
	public Keyword findKeyword(long keywordID){
		if(keywords != null){
			for(Keyword rpt: keywords){
				if(rpt.getKeywordId() == keywordID){
					return rpt;
				}
			}
		}
		return null;
	}
	
	public InsightWordData findInsightDta(String word){
		if(insightDatas != null){
			for(InsightWordData rpt: insightDatas){
				if(rpt.getBidword().equals(word)){
					return rpt;
				}
			}
		}
		return null;
	}
	
	public RptKeyword findLast3daysReport(long keywordID){
		return this.findByKeywordID(this.last3daysReport, keywordID);
	}
	
	public RptKeyword findLast7daysReport(long keywordID){
		return this.findByKeywordID(this.last3daysReport, keywordID);
	}
	
	private RptKeyword findByKeywordID(List<RptKeyword> rpts, long keywordID){
		if(rpts != null){
			for(RptKeyword rpt: rpts){
				if(rpt.getKeywordId() != null && rpt.getKeywordId() == keywordID){
					return rpt;
				}
			}
		}
		return null;
	}
}
